from wormbane.model.feature import Corridor, Doorway, Floor
from wormbane.model.rock import Rock
from wormbane.util.random_ import percent_chance

import random

def action_push(monster, target, game):
    game.write(monster, 'pushes', target)
    monster.time += 1
    if target.is_boulder:
        boulder_cell = target.env
        goal_cell = game.level.cells.get(2 * target.pos - monster.pos)
        if not goal_cell or not goal_cell.passable:
            game.write(target, 'will not move')
            return
        target.move_to(goal_cell)
        monster.move_to(boulder_cell)
        if goal_cell.feature.fillable:
            game.write(target, 'fills', goal_cell.feature)
            Floor().move_to(goal_cell)
            while goal_cell.top_item:
                goal_cell.top_item.move_to(goal_cell.feature)
            target.move_inv_to(goal_cell.feature)
            target.move_to(None)
